import math
import sys 
from com.l2jserver.gameserver import Announcements
from com.l2jserver.util import Rnd
from java.lang import System
from com.l2jserver.gameserver.model.quest import State
from com.l2jserver.gameserver.model.quest import QuestState
from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest
from com.l2jserver.gameserver.model.actor.instance import L2PcInstance
from com.l2jserver.gameserver.model.actor.instance import L2NpcInstance

#INSERT INTO `droplist` VALUES ('100', '1864', '100', '200', '1004', '500000');
#INSERT INTO `droplist` VALUES ('100', '1865', '300', '500', '1010', '500000');
#INSERT INTO `droplist` VALUES ('100', '1867', '300', '500', '1002', '500000');
#INSERT INTO `droplist` VALUES ('100', '1868', '100', '300', '1005', '500000');
#INSERT INTO `droplist` VALUES ('100', '1869', '50', '75', '1006', '500000');
#INSERT INTO `droplist` VALUES ('100', '1870', '50', '100', '1007', '500000');
#INSERT INTO `droplist` VALUES ('100', '1871', '50', '100', '1008', '500000');
#INSERT INTO `droplist` VALUES ('100', '1872', '200', '30', '1003', '500000');
#INSERT INTO `droplist` VALUES ('100', '1874', '30', '50', '1000', '500000');
#INSERT INTO `droplist` VALUES ('100', '1875', '20', '40', '106', '200000');
#INSERT INTO `droplist` VALUES ('100', '1876', '30', '60', '1001', '500000');
#INSERT INTO `droplist` VALUES ('100', '1887', '20', '40', '11', '500000');
#INSERT INTO `droplist` VALUES ('100', '1888', '20', '40', '11', '500000');
#INSERT INTO `droplist` VALUES ('100', '1894', '30', '60', '10', '500000');
#INSERT INTO `droplist` VALUES ('100', '4039', '10', '30', '104', '200000');
#INSERT INTO `droplist` VALUES ('100', '4040', '10', '30', '105', '200000');
#INSERT INTO `droplist` VALUES ('100', '4041', '10', '30', '103', '200000');
#INSERT INTO `droplist` VALUES ('100', '4042', '10', '30', '100', '200000');
#INSERT INTO `droplist` VALUES ('100', '4043', '10', '30', '101', '200000');
#INSERT INTO `droplist` VALUES ('100', '4044', '10', '30', '102', '200000');
#INSERT INTO `droplist` VALUES ('100', '5550', '10', '20', '10', '500000');

#--INSERT INTO `npc` VALUES ('100', '16052', 'Crazy Hungry Little Knight', '1', 'L2Pyros Event', '0', 'Monster3.chaos_golem', '25.00', '32.00', '70', 'male', 'L2RaidBoss', '40', '1500000', '5000', '1.50', '1.00', '80', '20', '73', '76', '70', '80', '0', '0', '2000', '250', '500', '500', '600', '500', '3819', '0', '0', '0', '25', '110', 'NULL', '0', '0', '0', 'FULL_PARTY', '0', '0', '0', 'balanced', 'false');

#--INSERT INTO `npcskills` VALUES ('100', '4197', '7');
#--INSERT INTO `npcskills` VALUES ('100', '4196', '7');
#--INSERT INTO `npcskills` VALUES ('100', '4201', '7');

eventInterval = 14400000 #millisecondi di attesa prima del prossimo respawn // 4 ore
FirstStart = 600000 #millisecondi dal restart // 10 minuti
vitaRaid = 10800000 #millisecondi di vita del raid // 3 ore

class raidbossEvent (JQuest):

    def __init__(self,id,name,descr):

 

        JQuest.__init__(self,id,name,descr)

        self.startQuestTimer("raidSpawn", FirstStart, None, None)

        self.RbSpawn = []

        self.RaidBosses ={

                0: {'name':"Crazy Hungry Little Knight" , 'id':100}, 

                1: {'name':"Crazy Hungry Little Knight" , 'id':100}, 

                } 

        self.RaidBossId = [ 100,100 ]

        self.RbCoords ={

                0: {'name':"at the western entrance of the Aden's Cemetary" , 'X':168671 , 'Y':20354 , 'Z':-3329}, 

                1: {'name':"at Gludin's Harbor" , 'X':-89418 , 'Y':150682 , 'Z':-3586},

                2: {'name':"near Giran Town on the way to Death Pass" , 'X':79412 , 'Y':142559 , 'Z':-3542},

                3: {'name':"near Talking Island Village" , 'X':-80860 , 'Y':247480 , 'Z':-3641},

                4: {'name':"at Giran's Harbor" , 'X':47024 , 'Y':186559 , 'Z':-3485}, 

                5: {'name':"near the bridge at south of Ice Merchant Cabin" , 'X':108822 , 'Y':-101844 , 'Z':-3563},

                6: {'name':"at North entrance of Enchanted Valley" , 'X':104088 , 'Y':32098 , 'Z':-3704}, 

                7: {'name':"near Dwarven Village" , 'X':115871 , 'Y':-175224 , 'Z':-1003}, 

                8: {'name':"near Rune Township" , 'X':39490 , 'Y':-55246 , 'Z':-1621}, 

                9: {'name':"near Hardin's Academy" , 'X':105614 , 'Y':108721 , 'Z':-3308}, 

                } 

 

 

    def onAdvEvent (self,event,npc,player):

        if event == "raidSpawn" : 

                ra = int(Rnd.get(2))

                rb = int(Rnd.get(7))

                self.RbSpawn = []

                raidboss = self.RaidBosses[ra]['name']

                location = self.RbCoords[rb]['name']

                annuncio = raidboss + " is just spawned " + location + " and will disappear in 1 hour, hurry up!"

                Announcements.getInstance().announceToAll(annuncio)

                self.RbSpawn = self.addSpawn(self.RaidBosses[ra]['id'],self.RbCoords[rb]['X'],self.RbCoords[rb]['Y'],self.RbCoords[rb]['Z'],0,False,0)

                print annuncio

                self.startQuestTimer("RbDespawn", vitaRaid, None, None)


 

        if event == "RbDespawn":

            annuncio = "No one have defeated the Crazy Hungry RaidBoss and now will disappear!"

            print annuncio

            Announcements.getInstance().announceToAll(annuncio)

            self.startQuestTimer("raidSpawn", eventInterval, None, None)

            self.RbSpawn.deleteMe()

 

 

 

    def onKill(self,npc,player,isPet):

        npcId = npc.getNpcId() 

        npcObjId = npc.getObjectId() 

        if npc == self.RbSpawn:

          if npc.getObjectId() ==  self.RbSpawn.getObjectId():

            self.startQuestTimer("raidSpawn", eventInterval, None, None)                             

            self.cancelQuestTimer("RbDespawn", None, None)

            annuncio = "Crazy Hungry RaidBoss has been killed!"

            print annuncio

            Announcements.getInstance().announceToAll(annuncio)

 

 

QUEST       = raidbossEvent(-1, "RandomBoss", "ai")

 

for i in QUEST.RaidBossId:

    QUEST.addKillId(i)

 

 

print "RandomBoss caricato"